package com.tq68.weixin.controller.image;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

import com.jfinal.core.Controller;

public class ImgController extends Controller{
	public void index(){
		String filename = getPara("filename");
		BufferedImage image = null;
		try {
			image = ImageIO.read(new File(filename));
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		HttpServletResponse response = getResponse();
		response.setHeader("Pragma","no-cache");
        response.setHeader("Cache-Control","no-cache");
        response.setDateHeader("Expires", 0);
        response.setContentType("image/jpeg");

        ServletOutputStream sos = null;
        try {
			sos = response.getOutputStream();
			ImageIO.write(image, "jpeg",sos);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		finally {
			if (sos != null)
				try {sos.close();} catch (IOException e) {e.printStackTrace();}
		}
        this.renderNull();
	}
}
